<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>留学生管理系统</title>
        <link rel="stylesheet" href="${path}/css/admin2.css">
        <link href="${path}/bower_components/datatables/media/css/jquery.dataTables.css" rel="stylesheet" />
 
        <style>
            .c{
                color: red;
            }
            @media screen and (max-width: 1400px) {
            div.dataTables_wrapper {
        width: 1000px;
        margin: -15px 0 10px 0;
    }
    #student{
             	margin: 10% auto;
                padding: 10px;
                width: 1000px;
                position: relative;
    			z-index: 2000;
    			background: #fff;
            }
            
    }
    @media screen and (min-width: 1600px) {
            div.dataTables_wrapper {
        width: 1500px;
        margin: -15px 0 10px 0;
    }
    #student{
             	margin: 10% auto;
                padding: 10px;
                width: 1500px;
                position: relative;
    			z-index: 2000;
    			background: #fff;
            }
            
    }
      @media screen and (min-width: 1400px)and (max-width: 1600px) {
            div.dataTables_wrapper {
        width: 1100px;
        margin: -15px 0 10px 0;
    }
    #student{
             	margin: 10% auto;
                padding: 10px;
                width: 1100px;
                position: relative;
    			z-index: 2000;
    			background: #fff;
            }
            
    }
            #team-modal{
                margin: 15% auto;
                padding: 10px;
                width: 400px;
            }
            #stu-modal{
                margin: 10% auto;
                padding: 10px;
                width: 400px;
            }
               #payStu-modal{
                margin: 12% auto;
                padding: 10px;
                width: 700px;
                position: relative;
    			z-index: 2000;
    			background: #fff;
            } 
            #addpay-modal{
                margin: -24% auto;
                padding: 10px;
                width: 400px;
                position: relative;
    			z-index: 4000;
    			background: #fff;
            }
            
        </style>
        <script>
            var _current_item = "#adminstumanage";
        </script>
        <script type="text/javascript" src="${path}/js/jquery.min.js"></script>
    </head>
    <body>
        <div id="above-mask">
            <div class="fileupload pannel hide" id="fileupload-pannel">
                <div class="close-container">
                    <a class="close" onclick="hide('#above-mask, #mask, #fileupload-pannel');">×</a>
                </div>
                <form action="${path}/adminstumanage/fileUpload" method="post" enctype="multipart/form-data" name="fileForm">
                    <div style="margin-top: 30px;"> 上传文件：（支持Excel 97-2003 工作簿 .xls格式文件）</div>
                    <input id="fileCover" class="left" readonly="readonly" placeholder="导入excel文件" type="text" style="width: 280px; height: 22px;">
                    <button onclick="$('#uploadFile').click();return false;" style="background: #aaa">浏览文件</button>
                    <input type="file" name="uploadFile" required="required" id="uploadFile" style="display:none" onchange="$('#fileCover').val($(this).val());">
                    <div>
                        <button type="submit" style="display: block; margin: 0 auto;">提交</button> 
                    </div>
                </form>
            </div>
            <div class="pannel hide" id="team-modal">
                <div class="close-container">
                    <a class="close" onclick="hide('#mask, #above-mask, #team-modal')">&times;</a>
                </div>
                
                    <table id="teamTab">			
                        <tr>
                            <td ><br />请选择导出学期:
                            <select name="teamExp" id="teamExp">
                            <#if term?exists>
                            <#list term as t>
                                        <option value='${t.termValue}'>${t.termValue}</option>
                             </#list>
                             </#if>          
                                    </select><br /><br />
                                    <button style="width:60px;margin-left:10px" onclick="hide('#mask, #above-mask, #team-modal');checkCouse('#stutable');">确定</button>
                    				<button style="width:60px;margin-left:40px" onclick="hide('#mask, #above-mask, #team-modal')">取消</button></td>
                           </td>
                        </tr>
                    </table>
                </form>
            </div>
            <!--student-->
            <div id="student" class="student hide pannel">
                        <div class="close-container"><a class="close" onclick="hide('#above-mask, #mask,#student')">×</a></div><br>
                        <div class="modal-body">
                            <table id="stu_1">
                                <thead>
                                    <tr>
                                        <td style="width:0px"><input type="hidden" id="checkstudent" ></td> 
                                        <td>护照号</td>
                                        <td>名</td>
                                        <td>姓</td>
                                        <td>专业</td> 
                                        <td>国籍</td>
                                        <td>签证到期日</td>
                                        <td>状态</td>
                                    </tr>
                                </thead>
                                <tbody>
                                    
                                </tbody>
                            </table>
                            <button  onclick="exportStu('#stu_1');hide('#above-mask, #mask,#student');">确定</button>
                        </div>
            </div>
            <!--student end-->
        	 <div class="pannel hide" id="stu-modal">
                <div class="close-container">
                    <a class="close" onclick="hide('#mask, #above-mask, #stu-modal')">&times;</a>
                </div>
                <form action="" method="post">
                    <table id="stuTab">
                        <tr><td>护照号</td><td></td></tr>
                        <tr><td>学号</td><td></td></tr>
                        <tr><td>姓</td><td></td></tr>
                        <tr><td>名</td><td></td></tr>
                        <tr><td>专业</td><td></td></tr>
                        <tr><td>入学年份</td><td></td></tr>
                        <tr><td>入学季度</td><td></td></tr>
                        <tr><td>国籍</td><td></td></tr>
                        <tr><td>电话</td><td></td></tr>
                        <tr><td>Email</td><td></td></tr>
                        <tr><td>签证到期日</td><td></td></tr>
                        <tr><td>宿舍号</td><td></td></tr>				
                        <tr>
                            <td colspan="2">
                                <!-- <button type="button" style="width:100px" onclick="hide('#mask, #above-mask, #stu-modal');show('#mask, #above-mask, #payStu-modal')">添加缴费记录</button>
                                <button type="button" style="margin-left:30px;width:100px" onclick="hide('#mask, #above-mask, #stu-modal');show('#mask, #above-mask,#visa-modal')">办理签证事务</button>
                                 --><button type="button"  id="singleStu" style="margin-left:140px;width:100px" >个人成绩</button>

                            </td>
                        </tr>
                    </table>		
                </form>
            </div>
        </div>
        <div id="mask"></div>
        <div id="header"></div>
        <div id="main">
            <div id="side-menu"></div>
            <div id="container">
                <div id="inner-border">
                    <button onclick="window.location.href='${path}/adminstumanage/fileDownload'">模板下载</button>
                    <button onclick="show('#mask, #above-mask, #fileupload-pannel')">批量导入</button>
                    <button onclick="checkChecked('#stutable');show('#above-mask, #mask,#student')">导出</button>
                    <button onclick="window.location.href = '${path}/adminstumanage/add'">新增学生</button>
                    <button onclick="show('#mask, #above-mask, #team-modal');">课表导出</button>
                   
                        <form action="${path}/adminstumanage/batch" name="myForm" method="post">
                            <input type="hidden" name="checkboxValue" id="checkboxValue">
                            <input type="hidden" name="none" id="none" value="1">
                            <input type="hidden" name="action" value="invalid">
                            <div id="error" style="display:none">${error!}</div> 
                            <table id="stutable" class="display nowrap"width="100%">
                                <thead>
                                    <tr>
                                        <th><input type="checkbox" id="selAll" onchange="checkAll(this,'#stutable')"></th>
                                        
                                        <th>护照号</th>
                                        <th>学号</th>
                                        <th>班级</th>
                                        <th>宿舍号</th>
                                        <th>名</th>
                                        <th>姓</th>
                                        <th>专业</th>
                                        <th>国籍</th>
                                        <th>签证到期日</th>
                                        <th>状态</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody id="tbody">
                                    <#if studentInfo?exists>
                                    <#list studentInfo as si>
                                    <tr> 
                                        <#if si.studentStatus==0>
                                        <td><input type="checkbox" value="${si.id}" name="stuCheckbox" id="stuCheckbox" ></td>
                                        <#else><td></td>
                                        </#if>                                        
                                        <td><a style="text-decoration:underline;color:#006699" id="${si.passportNo}"onclick="lookup(this);show('#mask, #above-mask, #stu-modal');return false;">${si.newpassportNo}</a></td>
                                       <td>${si.sNo}</td>
                                        <td>${si.clazz}</td>
                                        <td>${si.dormitoryNo}</td>
                                        <td>${si.firstName}</td>
                                        <td>${si.lastName}</td>
                                        <td>${si.majorName}</td>
                                        <td>${si.nationality}</td>
                                        <td name="data">${si.visaEndDate!}</td>
                                        <#if si.studentStatus==0>
                                        <td value="0">正常</td>
                                        <td>
                                            <button class="edit" onclick="window.location.href='${path}/adminstumanage/edit/${si.id}';return false;">编辑</button>
                                        </td>
                                        <#else>
                                        <td>失效</td>
                                        <td>
                                            <a href="${path}/adminstumanage/edit/${si.id}">查看</a>
                                        </td>
                                        </#if> 
                                        
                                    </tr>
                                    </#list>
                                    </#if>
                                </tbody>
                            </table>
                            <div style="margin-top:-62px"> 
                            <button class="cancel" onclick="getParam('stutable', 'checkboxValue');submitFun('invalid');">禁用学生</button>
                            <button onclick="getParam('stutable', 'checkboxValue');submitFun('re');">重置密码</button>
                        	</div>
                        </form>
                     
                </div> 
            </div> 
        </div>
                <div id="footer"></div>
        <script type="text/javascript" src="${path}/js/admin-main-appearance.js"></script>
        <script src="${path}/js/amazeui.min.js"></script>
        
        <!-- DataTables JavaScript -->
        <script src="${path}/bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetHiddenNodes.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetTd.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetTds.js"></script>
        <script src="${path}/bower_components/datatables-plugins/api/fnGetColumnData.js"></script>
        <script src="${path}/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js"></script>
        <script src="${path}/js/linkPage.js"></script>
        <script type="text/javascript" src="${path}/js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
    function submitFun(act)
    {
        myForm.action.value = act;
        myForm.submit();
    }
</script>
        <script>
            function ajaxnone() {
                /* 	var id = document.getElementById("").value;	 */
                $.ajax({
                    type: "post",
                    url: '${path}/adminstumanage/ajaxnone',
                    data: {
                        none: $('#none').val(),
                    },
                    datatype: "json",
                    success: function (data) {
                        for (var i = 0; i < data.length; i++)
                            $(document).ready(function () {
                                $('#stutable').dataTable().fnClearTable();
                                for (var i = 0; i < data.length; i++) {
                                    if (data[i]["studentStatus"] == 0) {
                                        $('#stutable').dataTable().fnAddData(['<input type="checkbox" value="' + data[i]["id"] + '" name="stuCheckbox" id="stuCheckbox" >', data[i]["passportNo"], data[i]["firstName"], data[i]["lastName"], data[i]["majorName"], data[i]["nationality"], data[i]["visaEndDate"], '正常', '<button  onclick="window.location.href=\'${path}/adminstumanage/edit/' + data[i]["id"] + '\';return false;">编辑</button>']);
                                    } else {
                                        $('#stutable').dataTable().fnAddData([' ', data[i]["passportNo"], data[i]["firstName"], data[i]["lastName"], data[i]["majorName"], data[i]["nationality"], data[i]["visaEndDate"], '失效', '<a href="${path}/adminstumanage/edit/' + data[i]["id"] + '">查看</button>']);
                                    }
                                }
                            });
                    }
                });
            }
            function lookup(node){
             $.ajax({
                    type: "get",
                    url: '${path}/adminstumanage/lookup',
                    data: {
                        passportNo: node.id,
                    },
                    datatype: "json",
                    success: function (data) {
                     // alert(JSON.stringify(data));
                     document.getElementById('stuTab').rows[0].cells[1].innerText = data["newpassportNo"];
                     document.getElementById('stuTab').rows[1].cells[1].innerText = data["sNo"];
                     document.getElementById('stuTab').rows[2].cells[1].innerText = data["firstName"];
                     document.getElementById('stuTab').rows[3].cells[1].innerText = data["lastName"];
                     document.getElementById('stuTab').rows[4].cells[1].innerText = data["majorName"];
                     document.getElementById('stuTab').rows[5].cells[1].innerText = data["eduStartDate"];
                     document.getElementById('stuTab').rows[6].cells[1].innerText = data["eduSeason"];
                     document.getElementById('stuTab').rows[7].cells[1].innerText = data["nationality"];
                     document.getElementById('stuTab').rows[8].cells[1].innerText = data["phone"];
                     document.getElementById('stuTab').rows[9].cells[1].innerText = data["mailbox"];
                     document.getElementById('stuTab').rows[10].cells[1].innerText = data["visaEndDate"];
                     document.getElementById('stuTab').rows[11].cells[1].innerText = data["dormitoryNo"];
                     setCookie("passportNo",data["passportNo"]);
                     setCookie("stuName",(data["firstName"]+" "+data["lastName"]));
                     $("#singleStu").on("click",function(){
                     window.location.href = '${path}/adminSingleStuScoreManage/index?passportNo='+data["passportNo"];
                     })
                     
                    }
                });
 
            }
        </script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#stutable').DataTable({
            responsive: true,
            "bSort": true,
            "aaSorting": [[ 2, "desc" ]],
            "aoColumnDefs": [ { "bSortable": false, "aTargets": [0,1,4,5,6,7,8,9,10,11] }],
            searching: true,
            "scrollX": true,
            "bLengthChange": false,
            "bRetrieve": true,
            "bFilter": true, //过滤功能
            "fnRowCallback": function (nRow, iDisplayIndex) {// 当创建了行，但还未绘制到屏幕上的时候调用，通常用于改变行的class风格 
                var now = new Date();
                var year = now.getFullYear();
                var month = (now.getMonth() + 1).toString();
                var day = (now.getDate()).toString();
                if (month.length == 1) {
                    month = "0" + month;
                }
                if (day.length == 1) {
                    day = "0" + day;
                }
                var DateTwo = year + "-" + month + "-" + day;

                var DateOne = $('td:eq(6)', nRow).text();
                //alert(DateOne);
                var OneMonth = DateOne.substring(5, DateOne.lastIndexOf('-'));
                var OneDay = DateOne.substring(DateOne.length, DateOne.lastIndexOf('-') + 1);
                var OneYear = DateOne.substring(0, DateOne.indexOf('-'));

                var TwoMonth = DateTwo.substring(5, DateTwo.lastIndexOf('-'));
                var TwoDay = DateTwo.substring(DateTwo.length, DateTwo.lastIndexOf('-') + 1);
                var TwoYear = DateTwo.substring(0, DateTwo.indexOf('-'));

                var cha = ((Date.parse(OneMonth + '/' + OneDay + '/' + OneYear) - Date.parse(TwoMonth + '/' + TwoDay + '/' + TwoYear)) / 86400000);
                //alert(Math.abs(cha));
                var minus = Math.abs(cha);
                if (minus <= 30) {
                    $('td:eq(6)', nRow).addClass("c");
                }
            }
        });
          
            $('#stu_1').DataTable({
            responsive: true,
            searching: true,
            "bSort": false,
            "bLengthChange": false,
            "bRetrieve": true,
            "bFilter": true, //过滤功能
            }); 
            
        
    });
    
/*    function stud_1(){
    $('#stu_1').DataTable({
            responsive: true,
            searching: true,
            "bSort": false,
            "bLengthChange": false,
            "bRetrieve": true,
            "bFilter": true, //过滤功能
            });
   } */
            
            /* select全选和全部取消*/
function checkAll(obj, tableid){
    var flag = obj.checked;
    var allNodes = getAllNodes(tableid);
    for (var tr in allNodes)
	{
		checkbox = allNodes[tr]["cells"][0]["childNodes"][0];
		if(checkbox!=null){
        if(checkbox["checked"] != flag){
            checkbox["checked"] = flag;
        }
        }
	}
}


function checkChecked(tableid){
    var allNodes = getAllNodes(tableid);
    $('#stu_1').dataTable().fnClearTable();
    for (var tr in allNodes)
	{
	
		var checkbox = allNodes[tr]["cells"][0]["childNodes"][0];
		if(checkbox!=null){
        if(checkbox["checked"] == true){
        var passportNo = allNodes[tr]["cells"][1]["childNodes"][0].id;
        var newpassportNo = allNodes[tr]["cells"][1]["childNodes"][0].innerHTML;
        var firName = allNodes[tr]["cells"][5].innerHTML;
        var lastName= allNodes[tr]["cells"][6].innerHTML;
        var major= allNodes[tr]["cells"][7].innerHTML;
        var inter= allNodes[tr]["cells"][8].innerHTML;
        var time= allNodes[tr]["cells"][9].innerHTML;
        var status= allNodes[tr]["cells"][10].innerHTML;
        $('#stu_1').dataTable().fnAddData(['<input type="hidden" value="'+passportNo+'"  id="'+passportNo+'" >',newpassportNo,firName,lastName,major,inter,time,status]);
            }    
            }               
	}
}
/* 学生课表导出 */
function checkCouse(tableid){
 var passportNo="",newpassportNo="";
    var allNodes = getAllNodes(tableid);
    for (var tr in allNodes)
	{
		var checkbox = allNodes[tr]["cells"][0]["childNodes"][0];
		if(checkbox!=null){
        if(checkbox["checked"] == true){
        passportNo += allNodes[tr]["cells"][1]["childNodes"][0].id+",";
        newpassportNo += allNodes[tr]["cells"][1]["childNodes"][0].innerHTML+","; 
	}
	}
	}
	alert(passportNo);
	var team = document.getElementById("teamExp").value;
	if(passportNo !=""){
	window.location.href = "${path}/adminstumanage/exportTimetable?passportNo="+passportNo+"&team="+team;}
	  $.ajax({
                    type: "post",
                    url: '${path}/adminstumanage/exportTimetable',
                    data: {
                    
                        passportNo:passportNo,
                        team:team,
                    },
                    datatype: "json",
                    success: function (data) {
                     
                    	alert("导出成功！");
                    }
                }); 

  
}

function exportStu(tableid){
var allNodes = getAllNodes(tableid);
var passportNo=[];

 for (var tr in allNodes)
	{
	passportNo[tr]=allNodes[tr]["cells"][0]["children"][0].id;
	} 
	var passportNo1=passportNo.join(",");
//alert(passportNo1);
  window.location.href = "${path}/studExport/exportExcel?passportNo="+passportNo1;
  return;
 /*$.ajax({
                    type: "get",
                    url: '${path}/studExport/exportExcel',
                    data: {
                        passportNo:passportNo1,
                    },
                    datatype: "json",
                    success: function (data) {
                     // alert(JSON.stringify(data));
                    
                    }
                });
	
 /* for(var i=0;i<passportNo.length;i++){
alert(passportNo[i]);
}  */
}
</script>
<script type="text/javascript">
    $(document).ready(function () {
        if ($("#error").html() != "") {
            Alert($("#error").html());
        }
        //alert($("#error").html());}
    });
    
            
</script> 
<script>
//自动关闭提示框  
    function Alert(str) {
        alert(str);
    }
</script>
<script>
    function nonestu() {
        var none = $("#none").val();
        if (none == 0) {
            myForm.none.value = 1;
        } else {
            myForm.none.value = 0;
        }
    }
</script>
</body>
</html>
